package oj;

import java.util.HashMap;
import java.util.Map;

public class Day3S {
    public int MoreThanHalfNum_Solution(int [] array) {
        HashMap<Integer,Integer> map=new HashMap<>();
        int len=array.length;
        for (int i = 0; i < len; i++) {
            map.put(array[i],(map.getOrDefault((array[i]),0))+1);
        }
        for(Map.Entry<Integer,Integer> entry:map.entrySet()){
            if(entry.getValue()>len/2){
                return entry.getKey();
            }
        }
     return -1;
    }
}
